import com.alibaba.fastjson.JSON;
import org.apache.commons.codec.binary.Base64;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class Submit {
    private String ecName;
    private String apId;
    private String secretKey;
    private String mobiles;
    private String content;
    private String sign;
    private String addSerial;
    private String MAC;

    public String getEcName() {
        return ecName;
    }

    public void setEcName(String ecName) {
        this.ecName = ecName;
    }

    public String getApId() {
        return apId;
    }

    public void setApId(String apId) {
        this.apId = apId;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getMobiles() {
        return mobiles;
    }

    public void setMobiles(String mobiles) {
        this.mobiles = mobiles;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getAddSerial() {
        return addSerial;
    }

    public void setAddSerial(String addSerial) {
        this.addSerial = addSerial;
    }

    public String getMac() {
        return MAC;
    }

    public void setMAC(String MAC) {
        this.MAC = MAC;
    }
}

public class Main {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        System.out.println(getSmsParam());
    }

    public static String getSmsParam() throws NoSuchAlgorithmException {
        Submit submit = new Submit();
        submit.setEcName("政企分公司测试");
        submit.setApId ("demo0");
        submit.setSecretKey("123qwe");
        submit.setMobiles ("13800138000");
        submit.setContent("移动改变生活");
        submit.setSign("DWItALe3A");
        submit.setAddSerial("");
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(submit.getEcName());
        stringBuffer.append(submit.getApId());
        stringBuffer.append(submit.getSecretKey());
        stringBuffer.append(submit.getMobiles());
        stringBuffer.append(submit.getContent());
        stringBuffer.append(submit.getSign());
        stringBuffer.append (submit.getAddSerial());

        String selfMac = encryptTOMD5(stringBuffer.toString());
        System.out.println("selfMac:"+selfMac);
        submit.setMAC(selfMac);
        String param = JSON.toJSONString(submit);
        System.out.println("param:"+param);

        //Base64加密
        return Base64.encodeBase64String(param.getBytes());
    }

    private static String encryptTOMD5(String input) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] messageDigest = md.digest(input.getBytes());
        BigInteger no = new BigInteger(1, messageDigest);
        StringBuilder hash = new StringBuilder(no.toString(16));
        while (hash.length() < 32) {
            hash.insert(0, "0");
        }
        System.out.println("md5() input="+input+",output="+ hash);
        return hash.toString();
    }
}
